function EditProfileAbout() {
	document.getElementById("edit_about_button").innerHTML="<input type=\"button\" name=\"submit\" value=\"Save About\" id=\"save_about_button\" onClick=\"EditSaveAbout();\" />" + "<input type=\"button\" name=\"submit\" value=\"Cancel\" onClick=\"EditCanceledAbout();\"/>";
	document.getElementById("text_aboutme").disabled =false;
}

function EditProfileAvatar() {
	document.getElementById("input_avatar").innerHTML="";
	document.getElementById("myfile").disabled=false;
}

function EditProfileEmail() {
	document.getElementById("edit_email_button").innerHTML="<input type=\"button\" name=\"submit\" value=\"Save Email\" id=\"save_email_button\" onClick=\"EditSaveEmail();\" />" + "<input type=\"button\" name=\"submit\" value=\"Cancel\" onClick=\"EditCanceledEmail();\"/>";
	document.getElementById("text_email").disabled =false;
}

function EditSaveAbout() {
	document.getElementById("edit_about_button").innerHTML="<input type=\"button\" name=\"submit\" value=\"Edit About\" onClick=\"EditProfileAbout();\"/>";
	document.getElementById("text_aboutme").disabled =true;
	saveAbout();
	// yg ini jgn lupa beneran diupdate ke database
}

function EditSaveAvatar() {
	document.getElementById("input_avatar").innerHTML="";
	document.getElementById("validavatar").innerHTML="";
	saveAvatar();
	// yg ini jgn lupa beneran diupdate ke database
}
	
function EditSaveEmail() {
	document.getElementById("edit_email_button").innerHTML="<input type=\"button\" name=\"submit\" value=\"Edit Email\" onClick=\"EditProfileEmail();\"/>";
	document.getElementById("text_email").disabled =true;
	document.getElementById("validemail").innerHTML="";
	saveEmail();
	// yg ini jgn lupa beneran diupdate ke database
}

function EditCanceledAbout() {
	document.getElementById("edit_about_button").innerHTML="<input type=\"button\" name=\"submit\" value=\"Edit About\" onClick=\"EditProfileAbout();\"/>";
	document.getElementById("text_aboutme").disabled =true;
	document.getElementById("text_aboutme").value = document.getElementById("hiddenaboutme").value;
	
	// yg ini jgn lupa balikin lg nilai email dan about me nya
}


function EditCanceledEmail() {
	document.getElementById("edit_email_button").innerHTML="<input type=\"button\" name=\"submit\" value=\"Edit Email\" onClick=\"EditProfileEmail();\"/>";
	document.getElementById("text_email").disabled =true;
	document.getElementById("text_email").value = document.getElementById("hiddenemail").value;
	document.getElementById("validemail").innerHTML="";
	document.getElementById("saveavatar_button").disabled=true;
	// yg ini jgn lupa balikin lg nilai email dan about me nya
}

function EmailChange() {
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			document.getElementById("validemail").innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText=="OK") {
				document.getElementById("save_email_button").disabled =false;
			} else {
				document.getElementById("save_email_button").disabled =true;
			}
		}
	}
	xmlhttp.open("GET","php/EditEmail.php?cek=email&email="+document.getElementById('text_email').value,true);
	xmlhttp.send();
}

function AvatarChange() {
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			document.getElementById("validavatar").innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText=="OK") {
				document.getElementById("saveavatar_button").disabled=false;
			} else {
				document.getElementById("saveavatar_button").disabled=true;
			}
		}
	}
	xmlhttp.open("GET","php/EditEmail.php?cek=avatar&avatar="+document.getElementById('myfile').value,true);
	xmlhttp.send();
}

function saveEmail() {
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.open("POST","php/saveEmail.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("email="+document.getElementById('text_email').value);
}

function saveAbout() {
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.open("POST","php/saveAbout.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("about="+document.getElementById('text_aboutme').value);
}

function saveAvatar() {
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.open("POST","php/saveAvatar.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("avatar_path="+document.getElementById('input_avatar').value);
}